import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

// 创建一个 store
const store = new Vuex.Store({
    // (1)初始 state 对象
    state:{
        hasLogin: false,
        token: "",
        company:"未知",
        userInfo: {
            Account: "未知",
            RealName: "未知",
            Id: "未知",
        },
    },
    // (2)定义一些mutation
    mutations:{
        change(state,company){
            state.company = company;
        },
        login(state,res) {
			var data=JSON.parse(res.data);
            state.hasLogin = true;
            state.token = res.token;
            state.userInfo.Id = data.Id;
			state.userInfo.Account = data.Account;
			state.userInfo.RealName = data.RealName;
			
        },
        logout(state) {
            state.hasLogin = false;
            state.token = "";
        },
        celarUserInfo(state) {
            state.userInfo = {
               "Account": "未知",
               "RealName": "未知",
               "Id": "未知",
            };
        },
    }
})

// 导出该模块:以便其他文件可对其进行使用
export default store